<template>
    <div>
        <div class='container'>


            <el-table
                :data='tableData'
                border
                class='table'
                ref='multipleTable'
                header-cell-class-name='table-header'
            >
                <el-table-column type='selection' width='55' align='center'></el-table-column>
                <el-table-column type='index' width='55' label='序号' align='center'></el-table-column>
                <el-table-column prop='indexId' hidden label='索引id'></el-table-column>

                <el-table-column prop='indexDesc' label='索引名称'></el-table-column>

                <el-table-column prop='num' label='剩余量' align='center'></el-table-column>

                <!--工具栏-->
                <el-table-column label='操作' width='180' align='center'>
                    <template slot-scope='scope'>
                        <el-button
                            type='text'
                            @click='rebulid(scope.$index, scope.row)'
                        >重建索引
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>


        </div>


    </div>
</template>

<script>
// import { fetchData } from '../../api/index';

export default {
    name: 'indexbulid',
    data() {
        return {
            tableData: [],
            setInterval: null
        };
    },
    mounted() {

    },
    //初始化函数
    created() {
        this.reflushTable();
    },
    methods: {
        reflushTable: function() {
            this.initTable();
            this.setInterval = setInterval(() => {
                    this.initTable();
                },
                5000
            );
        },
        initTable: function() {
            console.log('刷新');
            //每五秒刷新界面
            this.$http.get('/basicserver/indexController/reBulidLogIndexPage.json').then(res => {
                console.log(res);
                this.tableData = res.data.data;//数据
            });
        },
        //重建索引
        rebulid: function(index, row) {
            // 二次确认删除
            this.$confirm('确定要重建索引吗？', '提示', {
                type: 'warning'
            })
                .then(() => {
                    this.$http.get('/basicserver/indexController/reBulidLogIndex.json', row.indexId).then(res => {
                        if (res.data.status) {
                            this.$message.success('重建索引成功');

                        } else {
                            this.$message.success('重建索引失败');
                        }

                    });
                })
                .catch(() => {
                });
        }
    }
};
</script>

<style scoped>
.handle-box {
    margin-bottom: 20px;
}

.handle-select {
    width: 120px;
}

.handle-input {
    width: 300px;
    display: inline-block;
}

.table {
    width: 100%;
    font-size: 14px;
}

.red {
    color: #ff0000;
}

.mr10 {
    margin-right: 10px;
}

.table-td-thumb {
    display: block;
    margin: auto;
    width: 40px;
    height: 40px;
}
</style>
